<template>
  <div id="login">
    <div class="inner">
      <!-- 背景文字区域 -->
      <div class="text-wrap">
        <div class="text">
          <p class="text-p name">欢迎登陆</p>
          <p class="text-p name">数据运营管理平台</p>
        </div>
      </div>

      <!-- 登录表单区域 -->
      <div class="form-wrapper" >
        <div class="logo" >
          <img src="@/assets/img/logo.png" />
        </div>
        <h2 class="form-title">用户登录</h2>
        <el-form :model="data.form" :rules="rules" ref="formRef"  >
          <el-form-item label="账号" prop="username">
            <el-input  v-model="data.from.username" placeholder="请输入账号" />
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input type="password"  v-model="data.from.password"  placeholder="请输入密码"/>
          </el-form-item>
          <el-form-item prop="role"  label="用户选择">
            <el-select style="width:100%" placeholder="角色" v-model="data.from.role" >

              <el-option label="管理员" value="Root">管理员</el-option>
              <el-option label="客户" value="Student">客户</el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
                type="primary"
                class="submit-btn"
                @click="login"
                :loading="loading"
            >
              登录
            </el-button>
          </el-form-item>
          <div style="margin-top: 30px;text-align: right">还没有账号？请<a href="/register">注册</a></div>
        </el-form>
      </div>
    </div>

    <!-- 底部信息 -->
    <div class="bottom">
      <div class="bottom-item" v-for="(item, index) in bottomList" :key="index">
        <div class="logo">
          <img :src="item.icon" :alt="item.title" />
        </div>
        <div class="item-title">{{ item.title }}</div>
        <div class="item-intro">{{ item.intro }}</div>
      </div>
    </div>

    <!-- 固定链接 -->
    <div class="link">
      <a href="#">关于我们</a>
      <span>|</span>
      <a href="#">隐私政策</a>
    </div>
  </div>
</template>

<script setup>
import {reactive,ref} from "vue";
import request from "@/utils/request.js";

import {ElMessage} from "element-plus";

const data = reactive({
  from:{ role:'Root' }

})

const login =()=>{
  request.post('/login',data.from).then(res=>{
    console.log(res.data.code)


    if (res.data.code===1){
      localStorage.setItem('student-user',JSON.stringify(res.data))
      ElMessage.success('登入成功')
      location.href='/Course'  //跳转到主页

    }else{
      ElMessage.error('登入失败')

    }

  })

}
//表单校验？
</script>

<style scoped>
#login {
  width: 100%;
  min-height: 100vh;
  position: relative;
  background-size: 100% 100%;
  background-image: url("@/assets/img/wjq1.png");
  background-repeat: no-repeat;
}

#login .inner {
  min-width: 1400px;
  margin: 0 auto;
  position: relative;
}

#login .inner .text-wrap {
  position: absolute;
  height: 480px;
  top: 160px;
  width: 700px;
  box-sizing: border-box;
  margin-left: 8.3%;
  color: #fff;
  font-size: 50px;
  padding-top: 100px;
}

#login .inner .text-wrap .text-p {
  margin-bottom: 20px;
}

#login .inner .text-wrap .name {
  font-size: 50px;
}

#login .inner .text-wrap .slogan {
  font-size: 32px;
}

#login .inner .text {
  width: 700px;
}

#login .inner .form-wrapper {
  box-sizing: border-box;
  padding: 40px 40px 0 40px;
  width: 400px;
  height: 480px;
  background: #ffffff;
  box-shadow: none;
  border-radius: 6px;
  position: absolute;
  right: 160px;
  top: 160px;
}

#login .inner .form-wrapper .form-title {
  text-align: center;
  font-size: 28px;
  color: #323233;
  margin: 0px 0;
  font-weight: 600;
}

#login .inner .form-wrapper .logo {
  text-align: center;
  margin-bottom: 20px;
}

#login .inner .form-wrapper .logo img {
  width: 210px;
  height: 100px;
  object-fit: contain;
}

#login .inner .form-wrapper .valid-code-wrap {
  display: flex;
  align-items: center;
}

#login .inner .form-wrapper .valid-code-wrap .valid-code-input {
  flex: 1;
  margin-right: 10px;
}

#login .inner .form-wrapper .valid-code-wrap .mobile-validCode {
  font-size: 13px;
  color: #aaa;
  cursor: pointer;
}

#login .inner .form-wrapper .submit-btn {
  width: 100%;
  margin-top: 10px;
}

#login .bottom {
  display: flex;
  padding: 80px 0;
  background: rgba(255, 255, 255, 0.1);
}

#login .bottom .bottom-item {
  flex: 1;
  text-align: center;
  color: #fff;
}

#login .bottom .bottom-item .logo img {
  width: 40px;
  height: 40px;
}

#login .bottom .bottom-item .item-title {
  font-size: 16px;
  margin: 16px 0;
  font-weight: 500;
}

#login .bottom .bottom-item .item-intro {
  font-size: 14px;
  opacity: 0.8;
}

#login .link {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 12px;
}

#login .link a {
  color: #fff;
  text-decoration: underline;
  margin: 0 5px;
}

#login .link a:hover {
  opacity: 0.7;
}

#login .link span {
  margin: 0 5px;
}

@media screen and (min-width: 1700px) {
  #login .inner .text-wrap .text {
    margin-left: 200px;
  }

  #login .inner .form-wrapper {
    right: 320px;
  }
}
</style>
